﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SecsEquip;


namespace EquipSecs300
{
    public partial class EventView : CMyFormEx
    {
        private GEM_Even Event;
        private EventBtnTrig eventDetail;
        public EventView()
        {
            InitializeComponent();

            m_pViewName = "事件";
            InitCtrl();
        }


        // 更新数据
        public override void UpdateData()
        {
            // 从工具里面获取
            RefreshEventInfo();

            Event = secsEquipHelper.Even;
        }


        // 从工具里面获取
        void RefreshEventInfo()
        {
            listViewEvent.Items.Clear();
            List<EventInfo> listInfo = null;
            m_pSecs.EventGetList(ref listInfo);

            if (listInfo != null)
            {
                EventInfo ei;
                for (int i = 0; i < listInfo.Count; i++)
                {
                    ei = listInfo[i];
                    AddListData(UtilitiesConvert.StringToInt32(ei.CEID), ei.Name, ei.Description);
                }
            }
        }

        //初始化控件
        void InitCtrl()
        {
            listViewEvent.Columns.Add("CEID", 100, HorizontalAlignment.Left);
            listViewEvent.Columns.Add("Event Name", 250, HorizontalAlignment.Left);
            listViewEvent.Columns.Add("Description", 600, HorizontalAlignment.Left);
        }

        // 添加数据
        void AddListData(int CEID, string EventName, string Description)
        {
            listViewEvent.BeginUpdate();

            ListViewItem lvi = new ListViewItem();
            lvi.Text = CEID.ToString();

            lvi.SubItems.Add(EventName);
            lvi.SubItems.Add(Description);

            listViewEvent.Items.Add(lvi);

            listViewEvent.EndUpdate();
        }

        // 获取当前选择的ID
        private int GetCurSeletID()
        {
            int nCEID = 0;
            if (listViewEvent.SelectedItems.Count != 0)
            {
                string strCEID = listViewEvent.SelectedItems[0].Text;
                nCEID = UtilitiesConvert.StringToInt32(strCEID);
            }
            return nCEID;
        }

        // 发送事件
        private void buttonPosEvent_Click(object sender, EventArgs e)
        {
            int nEvent = GetCurSeletID();
            if (nEvent != 0)
            {
                m_pSecs.EventPos(nEvent);
            }
        }

        // 更新
        private void buttonUpdate_Click(object sender, EventArgs e)
        {
            // 从工具里面获取
            RefreshEventInfo();
        }

        
        private void btnEvenDetailView_Click(object sender, EventArgs e)
        {

            if (eventDetail == null || eventDetail.IsDisposed)
            {
                eventDetail = new EventBtnTrig(secsEquipHelper);
                eventDetail.Even = Event;
                eventDetail.UpdateData();
            }
            eventDetail.Show();

        }
    }
}
